using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections.Generic;

namespace ctem.gui
{
    public class ActorTypeConfig
    {
        public string TypeName = "TYPE_NAME";
        public string VisibleName = "VISIBLE_NAME";
        public string ClassName = "CLASS_NAME";
        public string Assembly = "PATH_TO_ASSEMBLY";
        public string Icon = "PATH_TO_ICON";
        public string HelpFile = "TAU.chm";
        public string HelpPath = "TAU.chm";
    }

    class ConfigManager
    {
        string path_to_ResourceFolder;// = ctem.gui.Properties.Settings.Default["path_to_ResourceFolder"].ToString();
        string path_to_KnowActorsTypes_config;
        string path_to_Images;
        string path_to_Model;
        string path_to_MainFolder;
        string path_to_help;
        List<ActorTypeConfig> know_actor_types;

        public ConfigManager()
        {
            path_to_MainFolder = Environment.CurrentDirectory;
            //if (path_to_ResourceFolder == "")
                path_to_ResourceFolder = path_to_MainFolder + "\\Resource";
            path_to_KnowActorsTypes_config = path_to_ResourceFolder + "\\actors\\KnowActorsTypes.xml";
            path_to_Images = path_to_ResourceFolder + "\\images";
            path_to_Model = path_to_ResourceFolder + "\\models";
            path_to_help = path_to_ResourceFolder + "\\help";
        }

        
        List<ActorTypeConfig> LoadKnowActorTypes()
        {
            List<ActorTypeConfig> list;
            using (FileStream fs = new FileStream(path_to_KnowActorsTypes_config, FileMode.Open))
            {
                XmlSerializer ser = new XmlSerializer(typeof(List<ActorTypeConfig>));
                list = (List<ActorTypeConfig>)ser.Deserialize(fs);
            }
            foreach (ActorTypeConfig atc in list)
            {
                if (!Path.IsPathRooted(atc.Assembly)) atc.Assembly = path_to_MainFolder + atc.Assembly;
                if (!Path.IsPathRooted(atc.Icon)) atc.Icon = path_to_MainFolder + atc.Icon;            
            }

            return list;
        }

        public List<ActorTypeConfig> KnowActorTypes
        {
            get { if (know_actor_types == null) { know_actor_types = LoadKnowActorTypes(); } return know_actor_types; }
        }

        public string ResourceFolder
        {
            get { return path_to_ResourceFolder; }
        }

        public string MainFolder
        {
            get { return path_to_MainFolder; }
        }

        public string ImagesFloder
        {
            get { return path_to_Images; }
        }

        public string ModelsFolder
        {
            get { return path_to_Model; }
        }

        public string HelpFolder
        {
            get { return path_to_help; }
        }

    }
}